import time

from machine import Pin

led = Pin(12, Pin.OUT)  # 构建LED对象
key = Pin(4, Pin.IN, Pin.PULL_UP)
state = 0  # LED引脚状态

while True:
    if key.value() == 0:
        time.sleep_ms(10)
        if key.value == 0:
            state = not state
            led.value(state)
            while not key.value():
                pass
